package com.huc.rest.utils;

import org.springframework.context.ApplicationContext;
import org.springframework.web.context.support.WebApplicationContextUtils;

import javax.servlet.ServletConfig;
import java.util.Map;

public class ContextUtils {
    private static ApplicationContext applicationContext;

    public static void init(ServletConfig config) {
        applicationContext = WebApplicationContextUtils.getWebApplicationContext(config.getServletContext());
    }

    public static Object getBean(String key) {
        return applicationContext.getBean(key);
    }

    public static <T> Map<String, T> getBean(Class<T> type) {
        return applicationContext.getBeansOfType(type) ;
    }
}
